﻿Public Class FrmABMBase
    Enum estado
        nuevo
        modificar
        eliminar
    End Enum
    Protected accion As estado = estado.nuevo
    
    Protected Sub habilitarDeshabilitarBotonesAcciones()
        btnNuevo.Enabled = Not btnNuevo.Enabled
        btnBuscar.Enabled = Not btnBuscar.Enabled
        btnGuardar.Enabled = Not btnGuardar.Enabled
        btnCancelar.Enabled = Not btnCancelar.Enabled
    End Sub

    Protected Sub habilitarDeshabilitarCampos()
        For Each campo As Control In GroupBoxDatos.Controls
            If Not campo Is Nothing And Not campo.GetType.Name = "Panel" And Not campo.GetType.Name = "Label" Then
                campo.Enabled = Not campo.Enabled
                If campo.Enabled = True And campo.TabIndex = 0 Then
                    campo.Focus()
                End If
            End If
        Next
    End Sub

    Protected Sub limpiarCampos()
        For Each obj As Control In GroupBoxDatos.Controls
            Select Case obj.GetType().Name.ToString
                Case "TextBox"
                    obj.Text = ""
                Case "MaskedTextBox"
                    obj.Text = ""
                Case "DataGridView"
                    'Dim gri As DataGridView = obj
                    'gri.DataSource = Nothing
                Case "CheckBox"
                    Dim chk As CheckBox = obj
                    chk.Checked = False
                Case "ComboBox"
                    Dim combo As ComboBox = obj
                    combo.SelectedIndex = 0
            End Select
        Next obj
    End Sub
    'Protected Function validarCampos() As Boolean
    '    Dim valido As Boolean = True
    '    Dim camposVacios(GroupBoxDatos.Controls.Count) As Control
    '    For p = 0 To camposVacios.Length - 1
    '        camposVacios(p) = Nothing
    '    Next
    '    For Each campo As Control In GroupBoxDatos.Controls
    '        If Not campo.GetType.Name = "Panel" And campo.Text = "" Then
    '            camposVacios(campo.TabIndex) = campo
    '            valido = False
    '        End If
    '    Next

    '    Dim campoFoco As Control = Nothing
    '    Dim mensajeCamposVacios As String = "Los campos "

    '    For i = 0 To camposVacios.Length - 1
    '        If Not camposVacios(i) Is Nothing Then
    '            mensajeCamposVacios += camposVacios(i).Tag & ", "
    '            If campoFoco Is Nothing Then
    '                campoFoco = camposVacios(i)
    '            End If
    '        End If
    '    Next

    '    mensajeCamposVacios += "están vacíos."
    '    MsgBox(mensajeCamposVacios, MsgBoxStyle.Exclamation, "Campos no Válidos")

    '    If Not campoFoco Is Nothing Then
    '        campoFoco.Focus()
    '    End If

    '    Return valido
    'End Function

    Private Sub btnNuevo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNuevo.Click
        limpiarCampos()
        habilitarDeshabilitarBotonesAcciones()
        habilitarDeshabilitarCampos()
    End Sub

    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        limpiarCampos()
        habilitarDeshabilitarBotonesAcciones()
        habilitarDeshabilitarCampos()
    End Sub

    Private Sub btnGuardar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGuardar.Click
        'If validarCampos() Then
        '    limpiarCampos()
        '    habilitarDeshabilitarBotonesAcciones()
        '    habilitarDeshabilitarCampos()
        'End If
    End Sub

    Private Sub btnBuscar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBuscar.Click
        
    End Sub

    Private Sub FrmABMBase_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Private Sub btnModificar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnModificar.Click
        habilitarDeshabilitarCampos()
        habilitarDeshabilitarBotonesAcciones()
    End Sub
End Class
